package com.hgsoft.service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.hgsoft.dao.BaseDao;
import com.hgsoft.util.Order;
import com.hgsoft.util.Pager;

public class BaseService<T extends Serializable> {
	
	private BaseDao<T> dao;
	
	public void save(T entity){
		dao.save(entity);
	}
	
	public void update(Object entity) {
		dao.update(entity);
	}
	
	public void delete(Object entity) {
		dao.delete(entity);
	}
	
	public void deleteById(Serializable id) {
		dao.delete(find(id));
	}

	public T find(Serializable id) {
		T entity = dao.find(id);
		return entity;
	}
	
	public List<T> findAll(){
		return dao.findAll(Order.asc("id"));
	}
	
	public List<T> findByPager(Pager pager){
		return getDao().findByPager(pager, Order.desc("id"));
	}
	
	public BaseDao<T> getDao() {
		return dao;
	}

	public void setDao(BaseDao<T> dao) {
		this.dao = dao;
	}
	
	@SuppressWarnings("rawtypes")
	public List query(Pager pager, Object object,Map dateMap) {
		// TODO Auto-generated method stub
		return getDao().query(pager,object,dateMap);
	}
}
